package com.ddm.pay;

import androidx.fragment.app.FragmentActivity;

public class GPH5PayShareManager {
    private static class GPH5PayShareManagerSingleton {
        private static final GPH5PayShareManager INSTANCE = new GPH5PayShareManager();

    }

    public static GPH5PayShareManager getInstance() {
        return GPH5PayShareManager.GPH5PayShareManagerSingleton.INSTANCE;
    }

    private GPH5PayShareManager() {
    }

    private DDMPayDialogFragment dDMPayDialogFragment;

    public void payAction(
            FragmentActivity fragmentActivity,
            String skuId,
            String skuName,
            String skuCoverImgUrl,
            String skuMarkPrice,
            String payAmount,
            int expireDay,
            String skuLevel,
            String uCode, GPH5PayShareListener gph5PayShareListener) {
        String url = "http://gupaoedu.net/ddmsh/buy/pay?ucode=%1$s&skuName=%2$s&expireDay=%3$d&skuId=%4$s&skuMarkPrice=%5$s&skuLevel=%6$s&payAmount=%7$s&skuCoverImgUrl=%8$s";
        url = String.format(url, uCode, skuName, expireDay, skuId, skuMarkPrice, skuLevel, payAmount, skuCoverImgUrl);
        if (dDMPayDialogFragment != null && dDMPayDialogFragment.isShowing()) {
            dDMPayDialogFragment.dismiss();

        }
        dDMPayDialogFragment = null;
        dDMPayDialogFragment = new DDMPayDialogFragment();
        dDMPayDialogFragment.initPayData(url, gph5PayShareListener);
        dDMPayDialogFragment.show(fragmentActivity.getSupportFragmentManager());
    }

    public boolean closePay() {
        if (dDMPayDialogFragment != null && dDMPayDialogFragment.isShowing()) {
            dDMPayDialogFragment.dismiss();
            return true;
        }
        return false;
    }

}
